package scripts;
import javax.swing.JOptionPane;
import bot.ScriptMethods;

public class VarrockPlatebodySmith extends ScriptMethods implements Runnable {

	private int plateID;
	private int barID;
	private int legID;

	public void start() {
		
		getAccountSettings();
		System.gc();
		
		Object[] options = {"Bronze", "Iron", "Steel", "Mithril", "Adamantite", "Runite"};
		
		String res1 = (String)JOptionPane.showInputDialog(null, "", "Varrock Platebody Smith", JOptionPane.PLAIN_MESSAGE, null, options, options[2]);

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
		
		if (res1.equals("Bronze")) {
			System.out.println("Bronze");
			barID = 169;
			plateID = 117;
			legID = 206;
		}
		if (res1.equals("Iron")) {
			System.out.println("Iron");
			barID = 170;
			plateID = 8;
			legID = 9;
		}
		if (res1.equals("Steel")) {
			System.out.println("Steel");
			barID = 171;
			plateID = 118;
			legID = 121;
		}
		if (res1.equals("Mithril")) {
			System.out.println("Mithril");
			barID = 173;
			plateID = 119;
			legID = 122;
		}
		if (res1.equals("Adamantite")) {
			System.out.println("Adamantite");
			barID = 174;
			plateID = 120;
			legID = 123;
		}
		if (res1.equals("Runite")) {
			System.out.println("Runite");
			barID = 408;
			plateID = 401;
			legID = 402;
		}
	}

	public void stop() {
		System.gc();
		scriptThread = null;
		scriptRunning = false;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();
				int[] bankDoor = getObjectById(64);
				if (bankDoor[0] != -1) {
					System.out.println("Bank door closed, opening.");
					atObject(bankDoor[1], bankDoor[2]);
					wait(random(1000, 1200));
				}
				if (itemCount(barID) >= 5 && !invContains(legID) && !isSleeping()) {
					useItemOnObject(148, 513, barID);
					wait(random(800, 1250));
				}
				if (questMenuOpen()) {
					answerQuestMenuStringContains("Armour", false);
					answerQuestMenuStringContains("Armour", false);
					answerQuestMenuStringEquals("Plate mail body (5 bars)", true);
					answerQuestMenuStringContains("access", true);
				}
				if (bankOpen()) {
					if (invContains(barID)) {
						depositAll(barID);
						wait(random(610, 750));
					}
					if (invContains(plateID)) {
						depositAll(plateID);
						wait(random(610, 750));
					}
					if (invContains(legID)) {
						depositAll(legID);
						wait(random(610, 750));	
					}
					withdraw(barID, 25);
					wait(random(610, 750));
					closeBank();
					wait(600);
				}
				if (itemCount(barID) < 5 || invContains(legID)) {
					if (!bankOpen()) {
						if (ourPlayerY() <= 506) {
							openBank();
							wait(2000);
						} else {
							walkToWait(151, 506);
						}
					}
				}
				wait(random(50, 80));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (!isLoggedIn())
			doLogin();
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
		if (getFightMode() != fightMode)
			setFightMode();
	}
}